package photogcalc.common;

import photogcalc.util.Formatter;

/**
 *
 * @author okkonena
 */
public class DistanceSlider extends Slider {

    private double stepWhenUnder1m = 0.1;
    private double stepWhenUnder10m = 0.5;
    private double stepWhenUnder20m = 1;
    private double stepWhenUnder50m = 2.5;
    private double stepWhenUnder100m = 5;
    private double defaultStep = 10;

    protected DistanceSlider(String label, double min, double max) {
        super(label, min, max);
    }

    public DistanceSlider(String label) {
        this(label, 0.1, 100);
    }

    protected void updatePosition(int direction) {
        if (direction == LEFT) {
            if (getValue() < 1.5) {
                setStep(stepWhenUnder1m);
            }
            else if (getValue() <= 10.5) {
                setStep(stepWhenUnder10m);
            }
            else if (getValue() <= 21) {
                setStep(stepWhenUnder20m);
            }
            else if (getValue() <= 52.5) {
                setStep(stepWhenUnder50m);
            }
            else if (getValue() <= 105) {
                setStep(stepWhenUnder100m);
            }
            else
                setStep(defaultStep);
        }
        else {
            if (getValue() > 96)
                setStep(defaultStep);
            else if (getValue() > 48)
                setStep(stepWhenUnder100m);
            else if (getValue() > 19)
                setStep(stepWhenUnder50m);
            else if (getValue() > 9.5)
                setStep(stepWhenUnder20m);
            else if (getValue() > 0.9) {
                setStep(stepWhenUnder10m);
            }
            else if (getValue() > 0.1) {
                setStep(stepWhenUnder1m);
            }
        }

        super.updatePosition(direction);
    }

    protected String getValueStr() {
        double val = super.getValue();

        if (val < 1) {
            return Formatter.format(val, 1)+"m";
        }
        else
            return super.getValueStr()+"m";
    }
}